package utils

import (
	"io"
	"golang.org/x/text/transform"
	"golang.org/x/text/encoding/simplifiedchinese"
	"bytes"
	"io/ioutil"
)

func GBKToUTF8(rd io.Reader) io.Reader {
	return transform.NewReader(rd, simplifiedchinese.GBK.NewDecoder())
}

func GB2312ToUTF8(rd io.Reader) io.Reader {
	return transform.NewReader(rd, simplifiedchinese.GB18030.NewDecoder())
}

func GBKByteToUTF8Bype(buf []byte) ([]byte, error) {
	reader := GBKToUTF8(bytes.NewReader(buf))
	return ioutil.ReadAll(reader)
}

func GB2312ByteToUTF8Byte(buf []byte) ([]byte, error) {
	reader := GB2312ToUTF8(bytes.NewReader(buf))
	return ioutil.ReadAll(reader)
}
